package com.panshi.common;



import com.panshi.api.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author :jiege
 * @description :
 * @create :2020-08-03 10:27:00
 */
@Component
public class CaptchaUtils {
    @Value("${server.servlet.session.timeout}")
    private Integer timeout;

    @Autowired
    private RedisUtil redisUtil;

    public Map<String,Object> createToken(String captcha){
        //生成一个token
        String cToken = UUID.randomUUID().toString();

        //生成验证码对应的token  以token为key  验证码为value存在redis中
        //StringRedisTemplate template = redisTemplate.getStringRedisTemplate();
        //ValueOperations<String, String> valueOperations = template.opsForValue();
       // String key = String.format(RedisKeys.CLIENT_TOKEN, cToken);
       // valueOperations.set(key, captcha);
        //template.expire(key, timeout, TimeUnit.MINUTES);
        redisUtil.set(cToken,captcha,timeout);
        Map<String, Object> map = new HashMap<>();
        map.put("cToken", cToken);
        map.put("expire", timeout);
        return map;
    }

}
